Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to generate a presigned url with a expiration time #117

Closed

Conversation

danielsanfr
Copy link
Contributor

@danielsanfr danielsanfr commented Nov 17, 2020

Hello people.

This PR solves the issue: #78

Let me know if everything is right or I need to do something else to accept this PR.

Unfortunately I can't test at DigitalOcean Spaces.

@ghost
Copy link

ghost commented Nov 17, 2020

Danger run resulted in 1 warning; to find out more, see the checks page.

Generated by 🚫 dangerJS

Signed-off-by: Daniel San <[email protected]>
@danielsanfr danielsanfr marked this pull request as ready for review November 17, 2020 04:01
index.js Outdated Show resolved Hide resolved
@danielsanfr danielsanfr force-pushed the feature/presigned-url branch from 3fb8650 to ea46045 Compare November 19, 2020 00:30
davimacedo
davimacedo previously approved these changes Nov 19, 2020
Copy link
Member

@davimacedo davimacedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me. @mtrezza any additional comment?

Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor requests.

Also, can you please add test cases?

README.md Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
@danielsanfr
Copy link
Contributor Author

@mtrezza I did 2 tests 😉 .

@danielsanfr
Copy link
Contributor Author

Hello people.

Let me know if I need to do anything else so that you can merge this PR.

@davimacedo
Copy link
Member

I think we can merge. @mtrezza do you think it is good now?

@mtrezza
Copy link
Member

mtrezza commented Nov 24, 2020

Just my comment on the parameters table thread.

@mtrezza
Copy link
Member

mtrezza commented Nov 24, 2020

I have added the parameter to the table and and improved the descriptions.

Now I wonder if we should add an additional test that ensures that the presigned URL only presigns for a getObject operation. Given the implications of presigned URLs, if there is a change in the code the presigned URL could give wide access to the S3 bucket, as described in the docs.

What's your opinion on that?

@danielsanfr
Copy link
Contributor Author

This can really be a problem.

I tried to generate a URL without passing a key in the hope of gaining access to the entire bucket, but the AWS SDK throws an exception. I also tried to put only one prefix as a key to try to access an entire "folder" from within the bucket, but when I open the URL the answer is that the key does not exist.

So, in case you read the bucket or folder, I don't see it as a problem.

Now for the case of writing to a file (or overwriting, via putObject operation), according to the documentation it can be a problem, but I don't know if I did the tests correctly locally, but the generated URL has no "visible" information that references the operation it allows.

That said, I may be mistaken, but I only see 2 "options" (that can be done together):

  1. Put a comment in the code saying that this operation should not be changed within this method;
  2. Create a variable or constant and create a test to validate that it has the value (getObject);

They are just suggestions, let me know if something really needs to be done or if we should make my suggestions or if you have any other ideas?

@mtrezza
Copy link
Member

mtrezza commented Nov 26, 2020

My two concerns are:

  • the Parse Server S3 Adapter code is changed and getObject is not set as allowed operation by mistake
  • the AWS SDK has a breaking change in the future and after upgrade the operations parameter is ignored and needs to be supplied in a different way

To address this I suggest to:

  • add a comment in our code
  • add a test case to spy on a method deep enough in the AWS SDK, preferably after some validation if there is any, ensuring that it receives getObject as allowed operation

@danielsanfr
Copy link
Contributor Author

Hello.

Could you add the comment to the code?

Regarding the test, let me know if this test is enough for you: danielsanfr@8266a66 . If so, I'll make the git cherry-pick.

@mtrezza
Copy link
Member

mtrezza commented Dec 4, 2020

The operation check should be a separate test case with a description that explains specifically what it is testing, to give this more significance.

Also, can you spy on a method within the S3 adapter and just call through or mock it?

The comment can just be a simple one that explains why the operation is specified and removing it can provide broad access to the S3 bucket, maybe with a like to the AWS S3 docs security section where this is explained.

Signed-off-by: Daniel San <[email protected]>
@davimacedo davimacedo requested a review from mtrezza December 11, 2020 22:50
@danielsanfr danielsanfr force-pushed the feature/presigned-url branch from 8edfec0 to 0873698 Compare February 2, 2021 12:41
@danielsanfr
Copy link
Contributor Author

Hello guys. I hope everyone is okay.

@mtrezza, I separated the test for the operation used and added the comment about security concerns in the code. I don't know how to "spy" on a method inside the S3 library, and I sincerely believe that it is not necessary.

I wonder if you can approve this PR or we still need to make more changes?

@mtrezza
Copy link
Member

mtrezza commented Jul 26, 2021

@danielsanfr Apologies for the long wait time, I have overlooked this in my notifications.

directAccess: true,
bucketPrefix: 'foo/bar/',
baseUrl: 'http://example.com/files',
['http://example.com/files', () => 'http://example.com/files'].forEach((baseUrl) => {
Copy link
Member

@mtrezza mtrezza Jul 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please refactor this for simplicity. We normally do not use such a pattern anywhere where we wrap a whole list of tests into a forEach, so this may cause confusion or test execution issues, e.g. with test randomization.

Then this should be good to merge.

@dblythy
Copy link
Member

dblythy commented Aug 24, 2021

@danielsanfr I have been using this branch on my project, and it's working well. Thanks for your efforts!!

@mtrezza
Copy link
Member

mtrezza commented Aug 24, 2021

@danielsanfr Could you address the open questions so we can merge this? I think there is just some minor refactoring left.

@mtrezza
Copy link
Member

mtrezza commented Aug 29, 2022

@danielsanfr @dblythy Could anyone do this minor refactor? Then we can merge this feature and make is available officially. And the PR needs a rebase I think.

@andrewalc
Copy link
Contributor

any updates on this? we really need this since its an important security feature for file downloads.

@mtrezza
Copy link
Member

mtrezza commented Mar 27, 2023

Would you want to create a new PR based on this PR and address the changes mentioned above?

@andrewalc
Copy link
Contributor

Just opened a PR here #180. I branched off this and refactored the one test you mentioned, let me know if i need to change anything else to get this through 👍

@danielsanfr danielsanfr deleted the feature/presigned-url branch May 17, 2023 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants